import { http } from '../utils/http/index'
import { LoginResponse, LoginRequest, UserDataResponse } from '../models/LoginModel'

// 获取手机验证码
export async function sendSmsCode(phone: string): Promise<void> {
  await http.get(`/portal/user/send_sms_code?phone=${phone}`)
}

// 手机号登录
export async function loginByPhone(phone: string, code: string): Promise<LoginResponse> {
  const requestData: LoginRequest = {
    phone,
    code
  }
  const response = await http.post('/portal/user/login/phone', requestData)
  return response as LoginResponse
}

// 获取用户信息
export async function getUserInfo(): Promise<UserDataResponse> {
  const response = await http.get('/portal/user/info')
  return response as UserDataResponse
}
